2
תגובות
This code works properly to make the ZIP file with the wanted files, except the filenames in the archive, which are in hebrew, have weird characters instead of the proper hebrew letters.
Meaning, $filesfordown = $_POST['GEMin']; are all hebrew utf-8 filenames. They are added successfully, however when opening the ZIP the filenames are corrupted.
<?php
$filesfordown = $_POST['GEMin'];
if(empty($filesfordown))
{
echo "No files were seleceted for download.";
}
else
{
$zip_name = "RMW." . time() . ".zip";
$zip = new ZipArchive;
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($filesfordown as $filefordown) {
$zip->addFile($filefordown);
}
$zip->close(); }
header('Content-Type: application/zip');
header("Content-disposition: attachment; filename='$zip_name'");
header('Content-Length: ' . filesize($zip_name));
readfile($zip_name);
ob_flush;
?>
$filesfordown = $_POST['GEMin'];
if(empty($filesfordown))
{
echo "No files were seleceted for download.";
}
else
{
$zip_name = "RMW." . time() . ".zip";
$zip = new ZipArchive;
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($filesfordown as $filefordown) {
$zip->addFile($filefordown);
}
$zip->close(); }
header('Content-Type: application/zip');
header("Content-disposition: attachment; filename='$zip_name'");
header('Content-Length: ' . filesize($zip_name));
readfile($zip_name);
ob_flush;
?>
I did some searching around, it seems that iconv, setlocalte, or mb_convert_encoding might help, but whatever I tried didn't work.
Any ideas?
2 תשובות
It is a bug with php (see #53948)
The comments suggest to upgrade your php and phpArchive pecl versions to the latest available
or try working around by converting to dos encoding:
$zip->addFile($filefordown, iconv("UTF-8","CP852",$filefordown));